//
//  UserModel.swift
//  HoneyBee
//
//  Created by point on 2018/1/29.
//  Copyright © 2018年 point. All rights reserved.
//

import UIKit

class UserModel: NSObject,NSCoding,Codable {
    //    @objc var address: String = ""
    //    @objc var checkCode: String = ""
    @objc var createTime: String = ""
    //    @objc var globalAreaCode: String = ""
    //    @objc var groupIds: Array<Int> = [Int]()
    @objc var headImg: String = ""
    @objc var id: Int = 0
    @objc var role: String = "" // 0 机构 1用户
    //    @objc var ip: String = ""
    //    @objc var phone: String = ""
    //    @objc var phoneKey: String = ""
    //    @objc var recommendPhone: String = ""
    @objc var tonken: String = ""
    @objc var updateTime: Int = 0
    @objc var userName: String = ""
    
    /// 机构ID
    @objc var institutionId: Int = 0
    
    /// 经度
    @objc var longitude: String = ""
    /// 纬度
    @objc var latitude: String = ""
    
    override init() {
        super.init()
    }
    
    
    
    
    // MARK:- 处理需要归档的字段
    
    func encode(with aCoder:NSCoder) {
        aCoder.encode(id, forKey:"id")
        aCoder.encode(institutionId, forKey:"institutionId")
        aCoder.encode(tonken, forKey:"tonken")
        aCoder.encode(longitude, forKey:"longitude")
        aCoder.encode(latitude, forKey:"latitude")
        aCoder.encode(role, forKey:"role")
    }
    
    func toJSON() -> Dictionary<String, Any> {
        return [
            "id": self.id as AnyObject,
            "role": self.role,
            "tonken": self.tonken,
            "userName": self.userName,
            "institutionId": self.institutionId,
            "headImg": self.headImg,
            "longitude": self.longitude,
            "latitude" : self.latitude
        ]
    }
    
    
    // MARK:- 处理需要解档的字段
    required init(coder aDecoder:NSCoder) {
        super.init()
        id = Int(aDecoder.decodeCInt(forKey: "id"))
        institutionId = Int(aDecoder.decodeCInt(forKey: "institutionId"))
        tonken = aDecoder.decodeObject(forKey:"tonken") as! String
        longitude = (aDecoder.decodeObject(forKey:"longitude") as? String) ?? ""
        latitude = (aDecoder.decodeObject(forKey:"latitude") as? String) ?? ""
        role = (aDecoder.decodeObject(forKey:"role") as? String) ?? ""
    }
}
